import React,{useEffect,useState} from 'react'
import { get } from '../../../util/get'
import { message,Card,Row,Col,Tag,PageHeader,List,Pagination} from 'antd';
import { post } from '../../../util/post'
import OrderVos from '../../../components/OrderVos'
import { useNavigate,useLocation } from 'react-router-dom';
import style from './index.module.css'

export default function Message() {
  const navigate = useNavigate()
  const  location =useLocation()
  const storeId =location.state
  const [list,setList]=useState([])
  const [total, setTotal] = useState(0)
  const [page, setPage] = useState(1)
  const [refresh,setRefresh]  = useState(false)
  const token = localStorage.getItem('TOKEN')
  useEffect(()=>{
    get(`/order/shop/list?shopId=${storeId}&page=${page}&limit=6`,token).then(res=>{
      const {code,page:{list,totalCount},msg}= res.data
      // console.log(res)
       if(!code){
        setList(list)
        setTotal(totalCount)
      }
      else message.error(msg)
    })
  },[token,storeId,page,refresh])
   
    return (
      <div>
        <div className={style.address_c}>
          <List
            className={style.addresslist}
            itemLayout="horizontal"
            bordered
            dataSource={list}
            renderItem={(item) => {
              return (
                <OrderVos r={refresh} setR={setRefresh} type={1} data = {item}></OrderVos>
              )
            }}
          />
        </div>
        <Pagination
            className={style.pagination}
            current={page} defaultPageSize={6}
            total={total} onChange={page => {
              setPage(page);
            }} />
      </div>
    )
}
